package cj.web.marriage.controllers;

import java.util.EnumSet;
import java.util.List;

import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;
import net.paoding.rose.web.var.Model;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import cj.web.admin.constants.MemuEnum;
import cj.web.login.controllers.BaseController;
import cj.web.marriage.constants.XQYHStatusEnum;
import cj.web.marriage.dao.PubYHDAO;
import cj.web.marriage.domain.PubYH;

@Path("/pubYH")
public class PubYHController extends BaseController{

	private static Logger logger = Logger.getLogger(PubYHController.class.getName());
	
	@Autowired
	private PubYHDAO pubYHDao;
	
	@Get("show")
	public String show(Model model,PubYH pubYH) {
		//MemuEnum
        model.add("MemuEnum",MemuEnum.xqggbkggyydd);
        model.add("XQYHStatusEnum",EnumSet.allOf(XQYHStatusEnum.class));
        return "/views/marriageXQ/pubYHList.vm";
	}

	@Post("getList")
	public String queryList(PubYH pubYH) {
		JSONObject jo = new JSONObject();
		
		List<PubYH> objs = pubYHDao.query(pubYH);
		int size = pubYHDao.querySize(pubYH);
		jo.put("data", objs);
		jo.put("draw", pubYH.getDraw());
		jo.put("recordsTotal", size);
		jo.put("recordsFiltered", size);
		
		return "@"+jo.toString();
	}
	
	@Get("success")
	public String success(Model model,@Param("id") int id){
		pubYHDao.updateStatusById(id, XQYHStatusEnum.doen.getValue());
		return "r:show";
	}
	
	@Get("fail")
	public String fail(Model model,@Param("id") int id){
		pubYHDao.updateStatusById(id, XQYHStatusEnum.fail.getValue());
		return "r:show";
	}
	
	@Get("deleteById")
	public String deleteById(Model model,@Param("id") int id){
		pubYHDao.deleteById(id);
		return "r:show";
	}
}